﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Web.Mvc;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using SportsStore.Domain.Abstract;
using SportsStore.Domain.Entities;
using SportsStore.WebUI.Controllers;

namespace SportsStore.UnitTests
{
    [TestClass]
    public class AdminTests
    {
        [TestMethod]
        public void Index_Contains_All_Products()
        {
            // Arrange - create the mock repository
            var mock = new Mock<IProductRepository>();
            mock.Setup( repo => repo.Products )
                .Returns( new Product[]
                {
                    new Product { ProductID = 1, Name = "P1" },
                    new Product { ProductID = 2, Name = "P2" },
                    new Product { ProductID = 3, Name = "P3" }
                }.AsQueryable() );

            // Arrange -  create a controller
            var adminController = new AdminController( mock.Object );

            // Action
            Product[] result = ( (IEnumerable<Product> ) adminController.Index().ViewData.Model ).ToArray();

            // Assert 
            Assert.AreEqual( result.Length, 3 );
            Assert.AreEqual( "P1", result[ 0 ].Name );
            Assert.AreEqual( "P2", result[ 1 ].Name );
            Assert.AreEqual( "P3", result[ 2 ].Name );
        }
    }
}
